package com.redpacketcover.rc.goods;

import io.reactivex.Observable;
import androidx.lifecycle.MutableLiveData;

import com.redpacketcover.rc.base.BaseResponseBean;
import com.redpacketcover.rc.base.BasicMode;
import com.redpacketcover.rc.bean.GoodsBean;
import com.redpacketcover.rc.bean.GoodsRecord;

import java.util.HashMap;
import java.util.List;

public class MatchMode extends BasicMode {


    /**
     * 获取商品列表
     */

    private MutableLiveData<BaseResponseBean<List<GoodsRecord>>> goodsData;

    public MutableLiveData<BaseResponseBean<List<GoodsRecord>>> getGoodsList(HashMap<String, Object> params) {
        if (goodsData == null) {
            goodsData = new MutableLiveData<>();
        }
        GoodsApiService service = getService(GoodsApiService.class);
        Observable<BaseResponseBean<List<GoodsRecord>>> observable = service.getGoodsList(params);
        getRequestData(observable, goodsData);
        return goodsData;
    }

    /**
     * 获取商品详情
     */

    private MutableLiveData<BaseResponseBean<GoodsRecord>> detailData;

    public MutableLiveData<BaseResponseBean<GoodsRecord>> getGoodsDetail(HashMap<String, Object> params) {
        if (detailData == null) {
            detailData = new MutableLiveData<>();
        }
        GoodsApiService service = getService(GoodsApiService.class);
        Observable<BaseResponseBean<GoodsRecord>> observable = service.getGoodsDetail(params);
        getRequestData(observable, detailData);
        return detailData;
    }

    /**
     * 获取购物车
     */

    private MutableLiveData<BaseResponseBean<GoodsRecord>> cartsData;

    public MutableLiveData<BaseResponseBean<GoodsRecord>> getCartsList(HashMap<String, Object> params) {
        if (cartsData == null) {
            cartsData = new MutableLiveData<>();
        }
        GoodsApiService service = getService(GoodsApiService.class);
        Observable<BaseResponseBean<GoodsRecord>> observable = service.getCartsList(params);
        getRequestData(observable, cartsData);
        return cartsData;
    }
}
